package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house_sale.domain.*;
import com.ruoyi.house_sale.service.IFinanceService;
import com.ruoyi.house_sale.service.IPaidTypeService;
import com.ruoyi.house_sale.service.ITicketService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.service.IEarnestmoneyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 诚意金管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-01
 */
@RestController
@RequestMapping("/house_sale/earnestmoney")
public class EarnestmoneyController extends BaseController
{
    @Autowired
    private IEarnestmoneyService earnestmoneyService;
    @Resource
    private IPaidTypeService paidtypeService;
    @Resource
    private ITicketService ticketService;
    @Resource
    private IFinanceService financeService;

    /**
     * 查询诚意金管理列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:list')")
    @GetMapping("/list")
    public TableDataInfo list(Earnestmoney earnestmoney)
    {
        startPage();
        List<Earnestmoney> list = earnestmoneyService.selectEarnestmoneyList(earnestmoney);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:list1')")
    @GetMapping("/list1/{buyid}")
    //@GetMapping(value = "/{buyid}")
    public TableDataInfo list1(@PathVariable("buyid") Long  buyid)
    {
        //System.out.println("buyid="+buyid);
        startPage();
        List<Earnestmoney> list = earnestmoneyService.selectEarnestmoneyByBuyId(buyid);
        return getDataTable(list);

    }
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:edit')")
    @PutMapping( "/contract")
    public AjaxResult contract(@RequestBody Earnestmoney form1)
    {
        return toAjax(earnestmoneyService.toContract(form1));

    }
    @PutMapping( "/invalid")
    public AjaxResult invalid(@RequestBody Earnestmoney form2)
    {
        return toAjax(earnestmoneyService.beInvalid(form2));

    }
    @GetMapping("/paidtypeList")
    public AjaxResult paidtypeList(){

        List<PaidType> list = paidtypeService.selectPaidTypeList(new PaidType());
        List<Ticket> list1 = ticketService.findAllTicket();
        AjaxResult ajax = AjaxResult.success();
        ajax.put("paidtypeList", list);
        ajax.put("ticketList", list1);
        return ajax;
    }

    /**
     * 导出诚意金管理列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:export')")
    @Log(title = "诚意金管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Earnestmoney earnestmoney)
    {
        List<Earnestmoney> list = earnestmoneyService.selectEarnestmoneyList(earnestmoney);
        ExcelUtil<Earnestmoney> util = new ExcelUtil<Earnestmoney>(Earnestmoney.class);
        util.exportExcel(response, list, "诚意金管理数据");
    }

    /**
     * 获取诚意金管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:query')")
    @GetMapping(value = "/{earnestid}")
    public AjaxResult getInfo(@PathVariable("earnestid") Long earnestid)
    {
        return AjaxResult.success(earnestmoneyService.selectEarnestmoneyByEarnestid(earnestid));
    }

    /**
     * 新增诚意金管理
     */
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:add')")
    @Log(title = "诚意金管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Earnestmoney earnestmoney)
    {
        return toAjax(earnestmoneyService.insertEarnestmoney(earnestmoney));
    }

    @PostMapping("/finance")
    public AjaxResult add1(@RequestBody Finance finance)
    {
        return toAjax(financeService.insertFinance(finance));
    }

    /**
     * 修改诚意金管理
     */
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:edit1')")
    @Log(title = "诚意金管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Earnestmoney earnestmoney)
    {
        return toAjax(earnestmoneyService.updateEarnestmoney(earnestmoney));
    }

    /**
     * 删除诚意金管理
     */
    @PreAuthorize("@ss.hasPermi('house_sale:earnestmoney:remove')")
    @Log(title = "诚意金管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{earnestids}")
    public AjaxResult remove(@PathVariable Long[] earnestids)
    {
        return toAjax(earnestmoneyService.deleteEarnestmoneyByEarnestids(earnestids));
    }
}
